package com.ian.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Witt
 * @version 1.0.0
 * @date 2022/4/30
 */
@Controller
public class LoginController {

    @GetMapping("/login")
    String login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        /*
        String currUsernameFromRequest = request.getRemoteUser();
        System.out.println("currUsernameFromRequest: " + currUsernameFromRequest); // output: currUsernameFromRequest: null
        boolean isAuthenticated = request.authenticate(response);
        System.out.println("isAuthenticated: " + isAuthenticated); // output: isAuthenticated: false
        */

        // 默认是重定向到 static 目录下；
        //   但是，此处因为整合了 thymeleaf 依赖，所以也可以重定向到 templates 目录下的 login.html
        //   坑1：另外，包含thymeleaf语法的html文件，必须在 templates 目录下，语法才能生效！
        return "login";
    }
}
